﻿/**
* jQuery.图片轮显插件.压缩版
* Written by jeffer (jxymnet AT gmail DOT com)
* Licensed under the WTFPL (http://pro.s7kj.com/jquery/jpics).
* Date: 2013/06/13
* @author jeffer
* @version 1.0
* @email jxymnet@gmail.com
**/
(function ($) {
    $.fn.extend({ jPics: function (config) {
        var defaultOption = { animationTime: 1000, turnsTime: 5000, width: 400, height: 300, borderWidth: 1, borderColor: '#333' }; var options = $.extend(defaultOption, config); $(this).each(function () {
            var timer1; var $this = $(this); var index = 1; var count = 0; var items = []; $this.addClass('jpics').css({ 'width': options.width, 'height': options.height, 'border-width': options.borderWidth, 'border-color': options.borderColor }); $this.append("<div class='title'></div>"); $('.title', $this).text($("a:eq(0)", $this).attr('title')).slideToggle(); $this.append("<div class='buttons'></div>"); $("a", $this).each(function (index) {
                var $item = $(this); $item.addClass("item"); if (index == 0) { $item.show(); }
                $('.buttons', $this).append('<span title="' + $item.attr('title') + '">' + (index + 1) + '</span>'); items.push($item);
            }); count = $("a.item", $this).size(); $('.buttons span:eq(0)', $this).addClass('action'); $('.buttons span', $this).click(function () { next($this, this); }).hover(function () { $(this).addClass('hover').siblings('span').removeClass('hover'); }, function () { $(this).removeClass('hover'); }); $($this).hover(function () { $('.title', $this).slideToggle(); clearInterval(timer1); }, function () {
                $('.title', $this).slideToggle(); timer1 = setInterval(function () {
                    if (index >= count) { index = 0; }
                    next($this, $('.buttons span:eq(' + index + ')', $this)); index++;
                }, options.turnsTime);
            }); timer1 = setInterval(function () {
                if (index >= count) { index = 0; }
                next($this, $('.buttons span:eq(' + index + ')', $this)); index++;
            }, options.turnsTime);
        }); function next(obj, button) { var _item = $('a.item:eq(' + $(button).index() + ')', obj); $(button).addClass('action').siblings('span').removeClass('action'); $('.title', obj).text(_item.attr('title')); _item.fadeIn(options.animationTime).siblings('a.item').fadeOut(options.animationTime); }
    }
    });
})(jQuery);